package com.fqy.thread.ticket01;

/**
 * User: fqy
 * Date: 2021/8/31
 * Time: 10:01
 * Describe: synchronized: 3个售票员 卖出 50张票
 *
 *
 */
public class TicketSale {

    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    System.out.println(ticket.saleTicket());
                }
            }
        }, "A").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    System.out.println(ticket.saleTicket());
                }
            }
        }, "B").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    System.out.println(ticket.saleTicket());
                }
            }
        }, "C").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    System.out.println(ticket.saleTicket());
                }
            }
        }, "D").start();
    }

}
